Skip to content

UI: more functions at 100% from our drafts #313, #327 and #328, with two header changes - #417

Merged
TheRedDaemon merged 10 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-C-round1-100
Nov 25, 2026
Merged

TheRedDaemon merged 10 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-C-round1-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

More UI functions at 100%, with two header commits. All of them come from our drafts #313, #327 and #328, which started from gynt's versions, and most were rewritten from the listing with his draft for the names. Each commit cites the drafts it builds on and credits him as co-author. reinitWindow stays in it at its measured 80.4%, with a remark in the status file: its only difference is register choice (#414).

Function Address Before After
VideoOptions::MenuItemActionHandler_VideoOptions_Main 0x00493E20 our draft #328, 61.5% (b2d7696); gynt's 61.5% (8725ec5) 100.0%
SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main 0x004C0CF0 our draft #328, 53.8% (53bea5f); gynt's 54.75% (25b481a) 100.0% (reccmp 99.2%, see below)
AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main 0x004B14C0 our draft #328, 60.5% (1f29978); gynt's 58.2% (8725ec5) 100.0%
General::MenuItemActionHandler_General_EventSlider 0x004B9E50 our draft #327, 88.0% (bddd6be); gynt's 83.26% (514b907) 100.0%
SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands 0x0042D140 our draft #328, 46.8% (07a33e2); gynt's 45.29% (b4b1f65) 100.0%

Below 100%: WindowAndDirectDraw::reinitWindow (0x004708F0), from our draft #313 (80.4%, 685b039; gynt's 56.9%, a8b64eb): 80.4% raw, 80.5% normalised, register choice only (#414).

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • Build of the run's files on main f489b72: 43 files (these functions, the run's other drafts and main's Allies_Main), with their function resolvers on. All read 100.0% except reinitWindow and SiegeAttackingForce, which are explained below. Main's MenuItemActionHandler_Allies_Main (0x004B12D0), the other user of the retyped global, stays at 100.0%.
  • Full build: main f489b72 with this branch and the other ready PR's branch, against a full build of main alone, every function resolver that has a .cpp switched on. The five functions of the first review round read as above (SiegeAttackingForce 99.2% raw from the address name), and no function on main reads lower; the header commits moved nothing. UI::Menu::handleMenuItems and Constructor_Menu show the known 0x11000000 naming artefact in the larger build only (same instructions). MapEditorLandscaping's GeneralButtons handler, which doesn't compile on main since the last sync, was left out (Reimplement 88 Map::TileMapState functions at 100% #366 changes it). After that build, the review fixes (all measured equal) and SingleplayerMapChoice's ButtonsAndHands were measured in a build of the branch's files: all 100.0%.
  • reinitWindow, reccmp 80.4% (80.5% normalised): both sides have the same 56 instructions, in the same order, with the same memory operands. Only eax, ecx and edx swap, on the reloads of windowHandle and on lea [esi+0xb8] (the second corner) before each push: twelve lines. if/else, nested and early-return shapes all compile to the same code. As TheRedDaemon asked, its status line carries the 80.4% with the remark Reimplemented, register choice only: the windowHandle load in front of the API calls takes another register (#414) (f93a5b9).
  • SiegeAttackingForce, reccmp 99.2%: the two lines that differ are the picture table's address 0x00B98782 (imh[first + picture - 1].height), 14 bytes before DAT_GMImageHeaders. reccmp prints it as a number on the original's side and as Instance<int,15544744>+2 (DAT_ButtonX + 2) on ours. That is a resolved-address name, as in main's TriggerInvasion_Main, which has the same two lines.
  • Checks: openshc-pr-fix finds nothing to change, and openshc-pr-check gives 0 ERROR.
  • Not run in game.

What got them to 100%

What paid most: one if/else-if chain with a single exit, the "other buttons" call last, a block written in each arm that uses it, and the case order inside a switch.

  • VideoOptions_Main: case 11 keeps the resolution in a local through the loop and stores it once after it. Case 18 calls setExtraActiveModalDialog in every arm of its chain, in the original's order, and popModalDialog is called in cases 17 and 18, so the compiler shares one tail jump. The loop is a for with its exit test in the header, which puts the test at the end of the round, as in the original.
  • SiegeAttackingForce render: one if/else-if chain that sets the draw buffer back once at the end; the compiler copies the store into the arms and pushes esi before the first branch, as the original does. renderGM is written in both arms that draw a unit's picture, each amount is drawn by a call in each arm of its colour test, and the row is -1 - button.
  • AlliesSendAndRequestGoods handler: button 100 holds the whole confirm path, and the other buttons' activateModalDialog comes last, which puts the return block where the original has it. The request path is one if/else-if chain that closes the dialog once, with the command stores and queueCommand written in both arms that send, the "not enough" arm first.
  • EventSlider: both range tests compare *currentValue > limit, and in the repeat slider's switch case 7 comes before case 4, as in the months slider's. That one move took it from register names only to every instruction.
  • SingleplayerMapChoice ButtonsAndHands: every case breaks to one store of the draw buffer at the end, each text has its own call in each colour arm, and case 78 is written out with its own store and return, so the switch keeps the original's range (179). The map-index sum is scroll offset plus relative selection; the other order swaps the two loads.

Behaviour fixed compared with the drafts

  • AlliesSendAndRequestGoods handler:
    • buttons 21 and 50 to 53 return after their one store, and any other button but 100 returns after opening the allies dialog. The draft went on into button 100's path;
    • button 102 (cancel) queues its command only when the send dialog is open and DAT_00df4284 is set. The draft always queued it;
    • when a request fails for want of a building or of room, the original plays at most the one warning that fits the fail state and closes the dialog. The draft played the third warning every time and, after a missing building, went on to the room test;
    • an accepted request queues the command and closes the dialog; the draft also played the "goods not sent" clip;
    • button 100 does nothing after the request path. The draft fell into the send path.

Header changes (a commit each)

  • DAT_SentOrRequestedGoodsAmount goes from undefined4 to int (958de6cae). The handler tests it as signed wherever it reads it: test ecx, ecx / jle at 0x004B15E6 (unsigned would be je), cmp eax, ecx / jge at 0x004B16ED, jge at 0x004B183A, jl at 0x004B1863 and cmp eax, esi / jge at 0x004B1870. As undefined4 each needs an (int) cast. Main's Allies_Main assigns to it and stays at 100.0%.
  • IngameInvasionEventItemContent's undefined1 padding_0xa4[4] becomes int field_0xa4 (c26ec0906). EventSlider reads it as one dword at 0x004B9E86 (mov eax, dword ptr [0x01667EEC]), the slider's highest value. Size and layout are unchanged, and nothing on main names the padding. The checker's CHECK that a field was "merged into a wider field" is a false positive here.

Main's declaration check will fail on this PR and label it until gynt syncs the two changes to main. Then we merge main in, and the check passes.

Kept as they are

  • Shapes the match needs: resource - 1 and good <= -1 in the Allies handler (the original compares with -1; good < 0 reads 0.9923 in quick_diff), index - 18 in SiegeAttackingForce, and case 7 before case 4 in EventSlider.
  • VideoOptions' supported flag stands in for a do-while: with the test in the for header the compiler places it where the original has it.
  • SetStorageMarketFailState gets goods[0] without +1, as in the original.
  • SiegeAttackingForce's rows 40 to 49 read SEC_Section1067.siegeEngineCounts[index - 40], which runs to [9] on a [6] array: rows 46 to 49 read tunnelersCount and past the struct. The binary does the same, with one base for all rows.

What some placeholders hold

  • DAT_00df4284 (0 or 1): set by Allies_Main when the ally asked for a good; the handler's cancel button tells that ally.
  • IngameInvasionEventItemContent::field_0xa4 / field_0xa8: the invasion slider's maximum and its amount.
  • MissionAestheticsDefinedData::field_0x345c: the order of the goods list (row to resource type).

Proposed, not changed here

  • Enums for DAT_00df4284 (0/1), storageMarketFailState values 5 to 10 and SetStorageMarketFailState's states 3 and 4.
  • Names: field_0xa4 (the invasion's maximum), field_0xa8 (its amount) and field_0x345c (the order of the goods list).
  • siegeEngineCounts: a union or [7], so rows 40 to 49 don't index past the array.

Leaving our drafts

Each commit removes the .cpp files and puts their status lines back to main's.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 8 commits November 17, 2026 20:43
…llocation only (sourcehold#414)

WindowAndDirectDraw::reinitWindow, moved out of our draft sourcehold#313 with one comment line added. The draft came from
gynt's version on his fork's reimpl/UI-Rendering-development (3768087 at 56.90%, a8b64eb at 56.9%, and
63cc49f of 2026-10-25, his newest commit on the file) and reached 80.4% in 685b039.

Register allocation only, per sourcehold#414: reccmp reads 80.4 (normalized 80.5), and the 56 instructions of both sides are
the same instructions in the same order with the same memory operands. What differs is which of eax, ecx and edx
holds each reload of windowHandle (and the address of the second corner) before it is pushed: eleven lines.
if/else, nested and early-return shapes of the two branches all compile to the same code.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
VideoOptions::MenuItemActionHandler_VideoOptions_Main, rewritten from the listing on top of gynt's draft: aae2c08
(57.14%, his fork's development), cd76e7f (57.7%, upstream's reimpl/UI-MenuItems), 8725ec5 (61.5%, his fork's
reimpl/UI-MenuItems-development) and 8ca7861 of 2026-10-27, his newest commit on the file (his fork's
reimpl/Wilps-2026-10-18: the same code with newer field names). Our mechanical pass b2d7696 in draft sourcehold#328 read
61.5% as well.

What the match needed:
- case 11 keeps the resolution in a local through the loop and stores it once after it; the draft worked on the
  field, which stores it in every round;
- case 18 reads the new resolution once and calls setExtraActiveModalDialog in every arm of the chain, in the
  original's order of arms. The draft set two position locals and called once, which shares the pushes. Two
  neighbouring arms with the same position joined by || read 0.8055 in quick_diff, so each resolution has its arm;
- popModalDialog is called at the end of case 18 and in case 17: the compiler shares the one tail jump;
- no goto and no position locals are left, and the loop is a for with its exit test in the header (a BOOLEnum
  that stands in for the original's do-while): the compiler puts the test at the end of the round, where the
  original has it.

Names instead of numbers: CT_WINDOWS_LIKE_CURSOR, CT_ANI_CURSOR and SS_NORMAL. The parameter is button, as in most
handlers on main; the buttons have no enum, so each case says what it does.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main, rewritten from the
listing on top of gynt's draft: ce671d7 and 37bf917 (40.1%, upstream's reimpl/UI-MenuItems), f0479fc,
b83dff2 and d7600c8 (44.39% to 52.82%, his fork's reimpl/UI-MenuItems), then 25b481a (54.75%), 9743554
(52.49%) and 6aa5d32 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development).
Our mechanical pass 7b18743 and 53bea5f in draft sourcehold#328 read 53.8%.

What the match needed:
- one if / else-if chain with the draw buffer set back once, at the end. The draft returned from every arm, each
  with its own store; written once, the compiler copies the store into the arms as the original has it, and esi
  is pushed before the first branch;
- renderGM for a unit's picture is written in both arms that draw one (rows 20 to 29 and 40 to 49). Shared after
  the chain it reads 0.7479 in quick_diff;
- the row is -1 - button (or esi, -1 / sub esi, eax), not -button - 1;
- every amount is drawn by a call in each arm of the colour test. One call with the colour as a ?: reads 0.9320
  (neg / sbb / and / add for the colour), with a colour local 0.9608.

Behaviour: none of the draft's forms differed in what they draw.

Readability, all measured equal: rows 20 to 29 read SEC_SiegeInformation[index - 20] and rows 40 to 49
SEC_Section1067.siegeEngineCounts[index - 40] (the draft indexed SEC_StartingResources[index + 5] for both, which
is the same address); the picture's height comes from DAT_GMImageHeaders as in TriggerInvasion_Main, not from a
cast on PTR_ARRAY_Unknown_UnitGMHeights; index >= 40 && index < 50 for the unsigned range test.

reccmp: 99.2% raw. The two lines that differ are the picture table's address 0x00B98782 (imh[first + picture - 1]
.height), 14 bytes before DAT_GMImageHeaders: reccmp prints it as a number on the original's side and, on ours, as
an offset from whichever variable of our DLL lies there (Instance<int,15544744>+2, DAT_ButtonX's instance). Only
the name of the resolved address differs, which the project records as 100% (TriggerInvasion_Main in sourcehold#349 has the
same two lines).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The amount the send / request goods dialog works with is compared as a signed value wherever it is read in
MenuItemActionHandler_AlliesSendAndRequestGoods_Main (0x004B14C0):
- 0x004B15E6: mov ecx, [0x00DF428C] / test ecx, ecx / jle: no amount chosen. An unsigned test would be je;
- 0x004B16ED: mov ecx, [0x00DF428C] / cmp eax, ecx / jge against the room getResourceSpace returned;
- 0x004B183A: cmp [the player's gold], esi / jge, and 0x004B1863 jl, 0x004B1870 cmp eax, esi / jge, with the
  amount in esi.
As undefined4 (unsigned) each of these needs an (int) cast. Its only user on main, MenuItemActionHandler_Allies_Main
(0x004B12D0), assigns to it and stays at 100.0% with the change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main, rewritten from the listing on top
of gynt's draft: c7cfed8 and 8ee5623 (32.9%, upstream's reimpl/UI-MenuItems), cbc63a3, 17cbc68 and
df54f4e (56.22% to 57.83%, his fork's reimpl/UI-MenuItems), 8725ec5 (58.2%) and 0e551f6 of 2026-11-02, his
newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 1f29978 in draft sourcehold#328 read 60.5%.

Behaviour, where the draft differed from the original:
- buttons 21 and 50 to 53 return after their one store, and any other button but 100 returns after opening the
  allies dialog. The draft went on from each of them into button 100's path;
- button 102 (cancel) queues its command only when the send dialog is open and DAT_00df4284 is set. The draft
  queued it always;
- when a request fails for want of a building or of room, the original plays at most the one warning that fits
  the fail state and closes the dialog. The draft played the third warning in every case and, after a missing
  building, went on to the room test;
- a request that is accepted queues the command and closes the dialog; the draft also played the "goods not
  sent" clip after it;
- button 100 does nothing after the request path. The draft fell into the send path.

What the match needed:
- button 100 holds the whole confirm path and the other buttons' activateModalDialog comes last, which puts the
  return block where the original has it (with the test turned round it read 0.9305 in quick_diff);
- the request path is one if / else-if chain that closes the dialog once at its end, with the five command
  stores and queueCommand written in both arms that send. The "not enough" arm comes first in the second
  (accepted first reads 0.9732);
- good <= -1, as the original compares with -1 (good < 0 reads 0.9923);
- the send path has one local for the resource, one for the type it is stored as, and one for the amount.

Uses the header commit before this one (the amount is an int), so no cast on it is left.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MenuItemActionHandler_General_EventSlider (0x004B9E50) reads the four bytes at 0xA4 as one int, the highest value
of the invasion's slider: mov eax, dword ptr [0x01667EEC] at 0x004B9E86 (DAT_MapPropertiesState's
invasionEventContent + 0xA4), which it then stores to *maxValue and clamps field_0xa8 with. The header had them as
undefined1 padding_0xa4[4], which needs *(int*)&...padding_0xa4[0] to read. Named field_0xa4 like its neighbours
field_0xa0 and field_0xa8; the struct's size and layout are unchanged, and nothing on main names the padding.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
General::MenuItemActionHandler_General_EventSlider, from gynt's draft: cbdee60 and 7c31877 (45.3%, upstream's
reimpl/UI-MenuItems), d0aa6c7 and 899dcd2 (55.93% and 69.21%, his fork's reimpl/UI-MenuItems), 514b907
(83.26%) and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development).
Our 2001534 and bddd6be in draft sourcehold#327 read 88.0%.

What the match needed, on top of the draft:
- the two range tests against the limit compare *currentValue > limit (cmp [ecx], eax / jle); the draft had
  limit < *currentValue, which swaps the operands;
- in the repeat slider's switch, case 7 comes before case 4, as it already did in the months slider's. That alone
  took it from register names only (0.9322 in quick_diff, the three small blocks of the months slider on rotated
  registers) to every instruction.

Readability, all measured equal: the lists of cases that only break are gone from both switches on the slider;
the two step cases use ++ and --, as the invasion slider's do, and no longer the limit's local; no cast on the
byte fields, read or written; the
parameters are slider and scrollbarEvent, as main's other slider handlers have the second; the amount sliders'
cases are written as their event type plus one (the function compares the type with slider - 1).

Uses the header commit before this one (the invasion's limit is an int field).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands, rewritten from the listing on
top of gynt's draft: 582f0a0 and 6918f23 (14.3%, upstream's reimpl/UI-MenuItems), 47663d0 (29.50%, his
fork's development), 1ff44c3 to eaf674d (20.55% to 44.64%, his fork's reimpl/UI-MenuItems), b4b1f65 (45.29%)
and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our
dcaa477, 53bea5f and 07a33e2 in draft sourcehold#328 read 46.8%.

Behaviour: unchanged. The draft cleared DAT_ButtonUnknownZero after the switch for buttons 2 and 65; here each of
the two clears it itself, before its call, as the original does. The draft's gotos into a shared text call are gone.

What the match needed:
- every case breaks to one store of the draw buffer at the end (the compiler copies it into the arms, with
  pop edi before it, as the original has it); the draft stored and returned in every arm;
- each text is drawn by a call of its own in each arm of the colour test, and renderBasicButton is called in
  each of button 74's three arms and button 77's two;
- case 78 is written out with its own store and return: the original's switch has a table entry for it, though
  it ends in the same block as the default (with a plain break, or left to the default, the range check reads
  cmp eax, 178 where the original has 179);
- the map-index sum in button 65 is DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected: the other
  order loads the two fields the other way round (reccmp 99.6%; quick_diff does not see it).

Readability, measured equal: X + W / 2 and X + W - 10 for the text positions.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gynt added a commit that referenced this pull request Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 24, 2026
@gynt
gynt requested a review from TheRedDaemon November 24, 2026 15:54
…oice only

WindowAndDirectDraw::reinitWindow's status line carries its measured percentage instead of 100% (the review asked
for the lower percentage with a remark). A narrow build of this branch's head c6df741, both resolver sets on,
sourcehold's reccmp with --ignore-security-cookie: 80.4% raw, 80.5% normalised. Both sides have the same 56
instructions in the same order with the same memory operands; the difference is which of eax, ecx and edx loads
this->windowHandle in front of the SetFocus, ClientToScreen and UpdateWindow calls (sourcehold#414). The code is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheRedDaemon
TheRedDaemon added this pull request to the merge queue Nov 25, 2026
Merged via the queue into sourcehold:main with commit e8f5c71 Nov 25, 2026
4 checks passed
Wilps93 pushed a commit to Wilps93/OpenSHC that referenced this pull request Nov 26, 2026
…rk (sourcehold#495)

TheRedDaemon asked on sourcehold#417 for a lower percentage, or the function taken out, where a match is short of 100 for a
known reason, and a remark in the status file either way. For our functions on main whose line says 100.0% but which
read lower in all-on full builds of main 71b70de and d348c31 (1f87a13 changes none of their files or headers):

- three read 100% until a header sync on main moved a register tie that depends on the declaration count (source
  unchanged): ShareGameSeedAndMultiplayerSettingsAndStartGame and UpdateUnitLossSpeechFeedback (6033692),
  LaunchSinglePlayerGameUnk (48f7e94). They get the measured % and a remark that says so;
- two differ in register choice only (sourcehold#416, recorded as 100% per sourcehold#414): they get the measured % and a "register
  choice only" remark in the form sourcehold#417 uses;
- ten differ only in names (call targets, loop-end and folded addresses, a type in a resolver's name). They stay at
  100.0% under AGENTS.md's rule and get the remark their line was missing.

Status file only.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants